package org.chen.controller;

import org.chen.common.vo.ResultVO;
import org.chen.dto.TtsInstructionTemplateDTO;
import org.chen.dto.TtsLanguageDTO;
import org.chen.dto.TtsModelDTO;
import org.chen.dto.TtsVoiceDTO;
import org.chen.service.TtsInstructionTemplateService;
import org.chen.service.TtsLanguageService;
import org.chen.service.TtsModelService;
import org.chen.service.TtsVoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/tts")
public class TtsController {

    @Autowired
    private TtsModelService modelService;
    
    @Autowired
    private TtsVoiceService voiceService;
    
    @Autowired
    private TtsInstructionTemplateService templateService;

    @Autowired
    private TtsLanguageService languageService;

    @GetMapping("/models")
    public ResultVO<List<TtsModelDTO>> getAllModels() {
        try {
            List<TtsModelDTO> allModels = modelService.getAllModels();
            return ResultVO.success("查询所有模型成功", allModels);
        } catch (Exception e) {
            return ResultVO.fail("查询所有模型失败：" + e.getMessage());
        }
    }

    @GetMapping("/voices")
    public ResultVO<List<TtsVoiceDTO>> getAllVoices() {
        try {
            List<TtsVoiceDTO> allVoices = voiceService.getAllVoices();
            return ResultVO.success("查询所有音色成功", allVoices);
        } catch (Exception e) {
            return ResultVO.fail("查询所有音色失败：" + e.getMessage());
        }
    }
    
    @GetMapping("/voices/{modelId}")
    public ResultVO<List<TtsVoiceDTO>> getVoicesByModelId(@PathVariable String modelId) {
        try {
            List<TtsVoiceDTO> voicesByModelId = voiceService.getVoicesByModelId(modelId);
            return ResultVO.success("查询模型成功", voicesByModelId);
        } catch (Exception e) {
            return ResultVO.fail("查询模型失败：" + e.getMessage());
        }
    }
    
    @GetMapping("/templates")
    public ResultVO<List<TtsInstructionTemplateDTO>> getAllTemplates() {
        try {
            List<TtsInstructionTemplateDTO> templates = templateService.getAllTemplates();
            return ResultVO.success("查询模板成功", templates);
        }catch (Exception e) {
            return ResultVO.fail("查询模板失败：" + e.getMessage());
        }
    }

    @GetMapping("/languages")
    public ResultVO<List<TtsLanguageDTO>> getAllLanguages() {
        try {
            List<TtsLanguageDTO> allLanguages = languageService.getAllLanguages();
            return ResultVO.success("查询语言成功", allLanguages);
        }catch (Exception e) {
            return ResultVO.fail("查询语言失败：" + e.getMessage());
        }
    }
}